package edu.szu.huhanpeng.doodlingFight.controller.mainHandler 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.model.ChessGroupProxy;
	import edu.szu.huhanpeng.doodlingFight.model.GameProxy;
	import edu.szu.huhanpeng.doodlingFight.model.ScoreProxy;
	import edu.szu.huhanpeng.doodlingFight.view.StagePanelMed;
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class SrCheckDone extends SimpleCommand implements ICommand, INotifier 
	{
		
		override public function execute(note:INotification):void 
		{
			var groupProxy:ChessGroupProxy = facade.retrieveProxy( ChessGroupProxy.NAME ) as ChessGroupProxy;
			if (groupProxy.getDone().length != 0) 
			{
				sendNotification( GlobalConst.noteName.MANAGE_DONE );
			}
			else
			{
				var gameProxy:GameProxy = facade.retrieveProxy(GameProxy.NAME) as GameProxy;
				var scoreProxy:ScoreProxy = facade.retrieveProxy(ScoreProxy.NAME) as ScoreProxy;
				
				if ( scoreProxy.score >= gameProxy.winScore ) 
				//if (true ) 
				{
					sendNotification( GlobalConst.noteName.GAME_OVER );
				}
				else
				{
					sendNotification( GlobalConst.noteName.TURN_PLAYER );				
					//sendNotification( GlobalConst.noteName.FIND_GROUP );
					//
					//
					//sendNotification( GlobalConst.noteName.UPDATE_ACTIONER );
					//( facade.retrieveMediator(StagePanelMed.NAME) as StagePanelMed ).enableInteract();
				}

			}
		}
		
	}

}